/*
 * @lc app=leetcode.cn id=1010 lang=javascript
 *
 * [1010] 总持续时间可被 60 整除的歌曲
 */

// @lc code=start
/**
 * @param {number[]} time
 * @return {number}
 */
var numPairsDivisibleBy60 = function(time) {
    let count=0
    let arr=[]
    for(let i=0;i<time.length;i++){
       for(let item of arr){
           if((time[i]+item)%60==0)count++
       }
       arr.push(time[i])
    }
    return count
};
// @lc code=end

numPairsDivisibleBy60 ([30,20,150,100,40])
var numPairsDivisibleBy60 = function(time) {
    let number = 0;
    let count = [];
    time.forEach(x=>{
        count[x%60] = (count[x%60]?count[x%60] + 1:1);
    })
    Object.keys(count).forEach(key=>{
        if(key == 0 || key == 30){
            number += count[key]*(count[key]-1)/2;
        }else{
            if(count[60-key] && key < 30){
                number += count[key]*count[60-key];
            }
        }
    })
    return number;
};
